package com.java.thread.demo.chapter1.sleep;

/**
 * Created by yiyongyao on 2017/12/19.
 */
public class TestMain {

    /**
     * seelp() 休眠测试
     * @param args
     */
    public static void main(String[] args) {
        //run();
        start();

    }



    /**
     * 子线程休眠2秒 当用run()方法执行时, 主线程main也被睡眠2秒
     *
     * 同时,子线程的线程也是由主线程执行的
     *
     * 总结 run方法只启动一个主线程进行执行所有线程
     */
    private static void run()
    {
        MyThreadRun run   = new MyThreadRun();
        System.out.println("main begin  " +  System.currentTimeMillis());
        Thread thread = new Thread(run);
        thread.run();
        System.out.println("main end  " +  System.currentTimeMillis());
    }

    /**
     * start 开启新线程
     */
    private static void start()
    {
        MyThreadStart start   = new MyThreadStart();
        System.out.println("main begin  " +  System.currentTimeMillis());
        Thread thread = new Thread(start);
        thread.start();
        System.out.println("main end  " +  System.currentTimeMillis());

    }


}
